<template>
  <q-page class="cc-admin">
    <div class="col bg-white shadow-2 q-pa-md q-ma-sm">
      <q-table flat color="primary" class="cross_table" separator="cell" :columns="columns" :data="list" row-key="id" :pagination.sync="pagination" :visible-columns="group" @request="query" :rows-per-page-options="[10, 20, 50, 100]" selection="multiple" :selected.sync="selected">
        <template v-slot:top="">
          <div class="row no-wrap full-width">
            <q-input clearable outlined dense placeholder="请输入关键字搜索" class="on-left" @input="query" debounce="500" v-model="key">
              <template #append>
                <q-btn flat round icon="search" color="primary" @click="query" :loading="loading">
                  <q-tooltip>搜索</q-tooltip>
                </q-btn>
              </template>
            </q-input>
            <q-space />
          </div>
        </template>
        <template #body-cell-opt="props">
          <q-td :props="props" :auto-width="true">
            <!-- <q-btn flat round dense color="primary" icon="edit" @click="edit(props.row)"> <q-tooltip>编辑</q-tooltip></q-btn> -->
            <!-- <q-btn flat round dense color="primary" icon="mdi-content-copy" @click="copy(props.row)">
              <q-tooltip>复制</q-tooltip>
            </q-btn> -->
            <q-btn flat round dense color="primary" icon="mdi-file-search-outline" @click="edit(props.row)">
              <q-tooltip>查看</q-tooltip>
            </q-btn>
            <btn-del label="试卷" @confirm="del(props.row)" />
          </q-td>
        </template>
      </q-table>
    </div>

    <q-dialog maximized flat persistent ref="dialog">
      <q-form @submit="submit2" class="dialog_card column">
        <h5 class="view_title justify-between q-px-md">
          查看试卷
          <q-btn dense outline round icon="clear" size="sm" v-close-popup />
        </h5>
        <q-scroll-area class="col">
          <!-- 试卷内容 -->
          <div class=" q-col-gutter-x-md dialog_form q-pa-md" style="display: flex;flex-direction: column;flex-grow: 1">
            <h5>一、选词填空</h5>
            <div class="row" style="display: flex;flex-grow: 1" v-for="(item, index) in form.blankQuestionsList" :key="item.id">
              <div class="col-6">
                <div v-html="item.questionStem" style="border: 1px solid #ccc; padding: 10px"></div>
              </div>
              <div class="col-6">
                <!-- 出题选项卡------------------------------------------------------------------------ -->
                <div style="height: 100%">
                  <q-splitter v-model="splitterModel">
                    <template v-slot:before>
                      <q-tabs v-model="tab2[index]" vertical class="text-teal">
                        <q-tab :name="itemTab.indexNum" icon="" :label="`第${index2 + 1}题`" v-for="(itemTab, index2) in item.questionList" :key="itemTab.indexNum" />
                      </q-tabs>
                    </template>

                    <template v-slot:after>
                      <q-tab-panels v-model="tab2[index]" animated swipeable vertical transition-prev="jump-up" transition-next="jump-up">
                        <q-tab-panel :name="question.indexNum" v-for="(question, index3) in item.questionList" :key="question.indexNum">
                          <div class="row">
                            <q-radio disable class="col-6" v-model="form.blankAnswer[index][index3]" color="cyan" :label="'A: ' + question.optionA" val='A' @input="changeCheck({ value: 'A', index, index3 })" />
                            <q-radio disable class="col-6" v-model="form.blankAnswer[index][index3]" color="cyan" :label="'B: ' + question.optionB" val='B' @input="changeCheck({ value: 'B', index, index3 })" />
                            <q-radio disable class="col-6" v-model="form.blankAnswer[index][index3]" color="cyan" :label="'C: ' + question.optionC" val='C' @input="changeCheck({ value: 'C', index, index3 })" />
                            <q-radio disable class="col-6" v-model="form.blankAnswer[index][index3]" color="cyan" :label="'D: ' + question.optionD" val='D' @input="changeCheck({ value: 'D', index, index3 })" />
                            <div class="answerdiv q-pl-xl">
                              <q-input prefix="正确答案：" disable outlined dense v-model="form.blankQuestionsList[index].questionList[index3].answer" type="text" class="answer" />
                              <q-icon name="mdi-check-bold" color="green" size="md" v-show="form.blankQuestionsList[index].questionList[index3].answer == form.blankAnswer[index][index3]"></q-icon>
                              <q-icon name="mdi-close" color="red" size="md" v-show="form.blankQuestionsList[index].questionList[index3].answer != form.blankAnswer[index][index3]"></q-icon>
                            </div>
                          </div>
                        </q-tab-panel>
                      </q-tab-panels>
                    </template>
                  </q-splitter>
                </div>
              </div>
            </div>
            <h5>二、阅读理解</h5>
            <div class="row" style="display: flex;flex-grow: 1" v-for="(item, index) in form.yueduQuestionsList" :key="item.id">
              <div class="col-6">
                <div v-html="item.questionStem" style="border: 1px solid #ccc; padding: 10px"></div>
              </div>
              <div class="col-6">
                <!-- 出题选项卡------------------------------------------------------------------------ -->
                <div style="height: 100%">
                  <q-splitter v-model="splitterModel">
                    <template v-slot:before>
                      <q-tabs v-model="tab3[index]" vertical class="text-teal">
                        <q-tab :name="itemTab.indexNum" icon="" :label="`第${index2 + 1}题`" v-for="(itemTab, index2) in item.questionList" :key="itemTab.indexNum" />
                      </q-tabs>
                    </template>

                    <template v-slot:after>
                      <q-tab-panels v-model="tab3[index]" animated swipeable vertical transition-prev="jump-up" transition-next="jump-up">
                        <q-tab-panel :name="question.indexNum" v-for="(question, index3) in item.questionList" :key="question.indexNum">
                          <div class="row">
                            <q-radio disable class="col-6" v-model="form.yueduAnswer[index][index3]" color="cyan" :label="'A: ' + question.optionA" val='A' @input="changeCheckyuedu({ value: 'A', index, index3 })" />
                            <q-radio disable class="col-6" v-model="form.yueduAnswer[index][index3]" color="cyan" :label="'B: ' + question.optionB" val='B' @input="changeCheckyuedu({ value: 'B', index, index3 })" />
                            <q-radio disable class="col-6" v-model="form.yueduAnswer[index][index3]" color="cyan" :label="'C: ' + question.optionC" val='C' @input="changeCheckyuedu({ value: 'C', index, index3 })" />
                            <q-radio disable class="col-6" v-model="form.yueduAnswer[index][index3]" color="cyan" :label="'D: ' + question.optionD" val='D' @input="changeCheckyuedu({ value: 'D', index, index3 })" />
                            <div class="answerdiv q-pl-xl">
                              <q-input prefix="正确答案：" disable outlined dense v-model="form.yueduQuestionsList[index].questionList[index3].answer" type="text" class="answer" />
                              <q-icon name="mdi-check-bold" color="green" size="md" v-show="form.yueduQuestionsList[index].questionList[index3].answer == form.yueduAnswer[index][index3]"></q-icon>
                              <q-icon name="mdi-close" color="red" size="md" v-show="form.yueduQuestionsList[index].questionList[index3].answer != form.yueduAnswer[index][index3]"></q-icon>
                            </div>
                          </div>
                        </q-tab-panel>
                      </q-tab-panels>
                    </template>
                  </q-splitter>
                </div>
              </div>
            </div>
            <h5>三、8选5</h5>
            <div class="row" style="display: flex;flex-grow: 1" v-for="(item, index) in form.selectQuestionsList" :key="item.id">
              <div class="col-6">
                <div v-html="item.questionStem" style="border: 1px solid #ccc; padding: 10px"></div>
              </div>
              <div class="col-6">
                <div style="height: 100%">
                  <!-- 出题选项卡------------------------------------------------------------------------ -->
                  <div class="">
                    <graph :orderNode="item.orderNode" :showList="false"></graph>
                  </div>
                  <div class="row col" style="min-height: 200px;width: 100%;display: inline-block">
                    <div class="col row q-px-md">
                      <div class="col">
                        <span>答案一：</span>
                        <q-input disable outlined dense v-model="form.selectAnswer[index].answer1" type="text" />
                      </div>
                      <div class="col row q-px-md">
                        <div class="col">
                          <span>正确答案：</span>
                          <q-input disable outlined dense v-model="form.selectQuestionsList[index].answer1" type="text" />
                        </div>
                      </div>
                      <div class="col-2 q-mt-md" style="">
                        <q-icon name="mdi-check-bold" color="green" size="md" v-show="form.selectQuestionsList[index].answer1 == form.selectAnswer[index].answer1"></q-icon>
                        <q-icon name="mdi-close" color="red" size="md" v-show="form.selectQuestionsList[index].answer1 != form.selectAnswer[index].answer1"></q-icon>
                      </div>
                    </div>
                    <div class="col row q-px-md">
                      <div class="col">
                        <span>答案二：</span>
                        <q-input disable outlined dense v-model="form.selectAnswer[index].answer2" type="text" />
                      </div>
                      <div class="col row q-px-md">
                        <div class="col">
                          <span>正确答案：</span>
                          <q-input disable outlined dense v-model="form.selectQuestionsList[index].answer2" type="text" />
                        </div>
                      </div>
                      <div class="col-2 q-mt-md">
                        <q-icon name="mdi-check-bold" color="green" size="md" v-show="form.selectQuestionsList[index].answer2 == form.selectAnswer[index].answer2"></q-icon>
                        <q-icon name="mdi-close" color="red" size="md" v-show="form.selectQuestionsList[index].answer2 != form.selectAnswer[index].answer2"></q-icon>
                      </div>
                    </div>
                    <div class="col row q-px-md">
                      <div class="col">
                        <span>答案三：</span>
                        <q-input disable outlined dense v-model="form.selectAnswer[index].answer3" type="text" />
                      </div>
                      <div class="col row q-px-md">
                        <div class="col">
                          <span>正确答案：</span>
                          <q-input disable outlined dense v-model="form.selectQuestionsList[index].answer3" type="text" />
                        </div>
                      </div>
                      <div class="col-2 q-mt-md" style="">
                        <q-icon name="mdi-check-bold" color="green" size="md" v-show="form.selectQuestionsList[index].answer3 == form.selectAnswer[index].answer3"></q-icon>
                        <q-icon name="mdi-close" color="red" size="md" v-show="form.selectQuestionsList[index].answer3 != form.selectAnswer[index].answer3"></q-icon>
                      </div>
                    </div>
                    <div class="col row q-px-md">
                      <div class="col">
                        <span>答案四：</span>
                        <q-input disable outlined dense v-model="form.selectAnswer[index].answer4" type="text" />
                      </div>
                      <div class="col row q-px-md">
                        <div class="col">
                          <span>正确答案：</span>
                          <q-input disable outlined dense v-model="form.selectQuestionsList[index].answer4" type="text" />
                        </div>
                      </div>
                      <div class="col-2 q-mt-md" style="">
                        <q-icon name="mdi-check-bold" color="green" size="md" v-show="form.selectQuestionsList[index].answer4 == form.selectAnswer[index].answer4"></q-icon>
                        <q-icon name="mdi-close" color="red" size="md" v-show="form.selectQuestionsList[index].answer4 != form.selectAnswer[index].answer4"></q-icon>
                      </div>
                    </div>
                    <div class="col row q-px-md">
                      <div class="col">
                        <span>答案五：</span>
                        <q-input disable outlined dense v-model="form.selectAnswer[index].answer5" type="text" />
                      </div>
                      <div class="col row q-px-md">
                        <div class="col">
                          <span>正确答案：</span>
                          <q-input disable outlined dense v-model="form.selectQuestionsList[index].answer5" type="text" />
                        </div>
                      </div>
                      <div class="col-2 q-mt-md" style="">
                        <q-icon name="mdi-check-bold" color="green" size="md" v-show="form.selectQuestionsList[index].answer5 == form.selectAnswer[index].answer5"></q-icon>
                        <q-icon name="mdi-close" color="red" size="md" v-show="form.selectQuestionsList[index].answer5 != form.selectAnswer[index].answer5"></q-icon>
                      </div>
                    </div>
                  </div>
                </div>

              </div>
            </div>
            <h5>四、翻译</h5>
            <div class="row" style="display: flex;flex-grow: 1" v-for="(item, index) in form.translateQuestionsList" :key="item.id">
              <div class="col-6">
                <div v-html="item.questionStem" style="border: 1px solid #ccc; padding: 10px"></div>
              </div>
              <div class="col-6">
                <!-- 出题选项卡------------------------------------------------------------------------ -->
                <div style="height: 100%">
                  <q-splitter v-model="splitterModel">
                    <template v-slot:before>
                      <q-tabs v-model="tab4[index]" vertical class="text-teal">
                        <q-tab :name="itemTab.indexNum" icon="" :label="`第${index2 + 1}题`" v-for="(itemTab, index2) in item.questionList" :key="itemTab.indexNum" />
                      </q-tabs>
                    </template>

                    <template v-slot:after>
                      <q-tab-panels v-model="tab4[index]" animated swipeable vertical transition-prev="jump-up" transition-next="jump-up">
                        <q-tab-panel :name="question.indexNum" v-for="(question, index3) in item.questionList" :key="question.indexNum">
                          <div class="column">
                            <div class="col">
                              <q-input disable outlined v-model="form.translateAnswer[index][index3]" type="textarea"></q-input>
                            </div>
                            <div class=" q-mt-md col">
                              <span>正确答案：</span>
                              <q-input outlined disable v-model="form.translateQuestionsList[index].questionList[index3].answer" type="textarea" class="answer" />
                              <!-- <q-icon name="mdi-check-bold" color="green" size="md" v-show="question.answer == form.blankAnswer[index][index3]"></q-icon> -->
                              <!-- <q-icon name="mdi-close" color="red" size="md" v-show="question.answer != form.blankAnswer[index][index3]"></q-icon> -->
                            </div>
                          </div>
                        </q-tab-panel>
                      </q-tab-panels>
                    </template>
                  </q-splitter>
                </div>
              </div>
            </div>
            <h5>五、写作</h5>
            <div class="column" style="display: flex; flex-grow: 1" v-for="(item, index) in form.writeQuestionsList" :key="item.id">
              <div class="col-6 q-px-md">
                <div v-html="item.questionStem" style="border: 1px solid #ccc; padding: 10px"></div>
              </div>
              <div class="col-6">
                <!-- 出题选项卡------------------------------------------------------------------------ -->
                <div class="col q-px-md">
                  <span>答案：</span>
                  <q-input outlined dense v-model="form.writeAnswer[index]" autogrow type="textarea" />
                </div>
                <div class="col q-px-md">
                  <span>范文：</span>
                  <q-input outlined dense v-model="item.answer" autogrow type="textarea" />
                </div>
              </div>
            </div>
          </div>
        </q-scroll-area>
        <div class="row justify-center q-pa-md">
          <q-btn outline color="primary" icon="mdi-close-thick" label="关闭" v-close-popup />
          <!-- <q-btn class="q-mx-md" color="primary" icon="mdi-check-bold" label="提交" :loading="loading" type="submit2" /> -->
        </div>
      </q-form>
    </q-dialog>
    <confirm ref="confirmDialog" :msg="confirmMsg" @confirm="deleteBatch()" />
    <q-inner-loading :showing="loading">
      <q-spinner-gears size="50px" color="primary" />
    </q-inner-loading>
  </q-page>
</template>

<script>
import { IndexMixin } from 'boot/mixins';
import { getDictLabel } from 'boot/dictionary';
import confirm from 'components/confirm';
import 'katex/dist/katex.min.css';
import katex from 'katex';
import { before } from 'lodash';

export default {
  name: 'EnglishViewPaper',
  mixins: [IndexMixin],
  components: {
    confirm,
  },
  data() {
    return {
      catalog: '03',
      tab: '0101',
      tab2: [],
      tab3: [],
      tab4: [],
      index: 0,
      splitterModel: 20,
      form: {
        id: '',
        subjectId: '03',
        subjectText: '英语',
        blankIds: '',
        yueduIds: '',
        selectIds: '',
        translateIds: '',
        writeIds: '',
        paperName: '',
        blankQuestionsList: [],
        yueduQuestionsList: [],
        selectQuestionsList: [],
        translateQuestionsList: [],
        writeQuestionsList: [],
        blankAnswer: [],
        yueduAnswer: [],
        selectAnswer: [],
        translateAnswer: [],
        writeAnswer: [],
      },
      columns: [
        {
          name: 'index',
          align: 'center',
          label: '序号',
          field: 'index',
        },
        {
          name: 'paperName',
          align: 'center',
          label: '试卷名称',
          field: 'paperName',
        },
        {
          name: 'opt',
          align: 'center',
          label: '操作',
          field: 'id',
        },
      ],
      showQuery: true,
      headers: [{ name: 'Authorization', value: localStorage.Authorization }],
      uploadUrl: `${process.env.SERVER_URL}${process.env.BASE_URL}/sys/common/upload`,
      imgUrl: `${process.env.SERVER_URL}${process.env.BASE_URL}/sys/common/static`,
      url: {
        list: '/exam/paperAnswerEnglish/viewList2',
      },
    };
  },
  methods: {
    logblankResult() {
      console.log(this.form);
    },
    submit2() {
      this.$axios
        .post(this.url.editshape, this.form)
        .then((r) => {
          this.$info(r.message);
          this.$refs.dialog.hide();
        })
        .finally(() => {
          this.query();
        });
    },

    renderMath(str) {
      return katex.renderToString(str, {
        throwOnError: false,
      });
    },
    getDictLabel,
    initDict() {

    },
    editAfter() {
      if (this.form.blankResult.length > 0) {
        return;
      }
      this.form.blankResult = [];
      for (let i = 0; i < this.form.blankQuestionsList.length; i++) {
        this.form.blankResult.push('');
      }
      console.log(this.form);
    },
  },
  mounted() {
    this.initDict();
  },
};
</script>

<style lang="stylus">
.answerdiv
  white-space normal
  word-wrap break-word
  overflow-wrap break-word
  display inline-block
  .answer
    display inline-flex
    max-width 500px
.blankAnalysis::before
  content '解析：'
  white-space pre-wrap
</style>
